<?php
class CMS_Models_LangProduct extends Zend_Db_Table_Abstract
{
	protected $_name = "lang_product";
	
	public function __construct( )
   	{
   	 parent::__construct(array('table' =>$this->_name));
   	}
	
    public function getAll()
    {
      $products = $this->fetchAll();
   	  return $products;
    }
    
    public function getProductsByLang($lang)
    {
      $sql = "select p.*,pxi.* from product p
      		  inner join lang_product pxi
      		  on ( pxi.id_product = p.id )
      		  where pxi.lang = '$lang' ";
      return TN_Db::getInstance()->fetchAll($sql);
    }

    public function getProductsByCategory($c, $lang)
    {
        $sql = "select p.*,pxi.* from product p
      		  inner join lang_product pxi
      		  on ( pxi.id_product = p.id )
      		  where pxi.lang = '$lang' and p.id_category = '$c'";
        
        return TN_Db::getInstance()->fetchAll($sql);
    }
    
    /*
     * devuelve el contenido, asociado a los datos de la tabla content
     */
    public function getProductByKey($id, $lang)
    {
      $sql = "select p.*,pxi.* from product p
      		  inner join lang_product pxi
      		  on ( pxi.id_product = p.id )
      		  where pxi.lang = '$lang' and pxi.id_product = '$id'";
      return TN_Db::getInstance()->fetchRow($sql);
    }
    /**
     * Devuelve el  contenido para obtener el registro de la tabla
     * @param unknown_type $id
     */
    public function getProductById($id, $lang)
    {
      $product = $this->fetchRow("id_product = '$id' and lang = '$lang'");
      return $product;
    }
}